package com.hzhc.controller.sysmanage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.entity.SysWxRole;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.SysWxRoleService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.vo.SysWxRoleVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 微信角色管理
 *
 * @author 功不唐捐
 * @since 2024-04-07
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysWxRole")
public class SysWxRoleController extends BaseController {

    private final SysWxRoleService sysWxRoleService;

    /**
     * 微信角色列表
     * @param vo
     * @return
     */
    @PostMapping("/getList")
    public ResultUtil<List<SysWxRole>> getList(@RequestBody SysWxRoleVo vo) {
        Page<SysWxRole> pagination = new Page<SysWxRole>(vo.getPageIndex(), vo.getPageSize());
        List<SysWxRole> list = sysWxRoleService.getList(pagination, vo);
        return ResultUtil.build(list,pagination.getTotal(), pagination.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 微信角色校验
     * @param data
     * @return
     */
    @RequestMapping("/checkWxName")
    public ResultUtil<T> checkWxName(@RequestBody SysWxRoleVo data) {
        return sysWxRoleService.checkWxName(data);
    }

    /**
     * 微信角色新增
     * @param request
     * @param sysWxRole
     * @return
     */
    @PostMapping("/addRet")
    @SysTemLog(operModul = "微信角色", operType = "新增", operDesc = "添加", modular = "PC")
    public ResultUtil<T> addRet(HttpServletRequest request,@RequestBody SysWxRole sysWxRole) {
        ResultUtil<T> result = sysWxRoleService.addRet(request, sysWxRole);
        return result;
    }

    /**
     * 微信角色删除
     * @param request
     * @return
     */
    @PostMapping("/delete/{id}")
    @SysTemLog(operModul = "微信角色", operType = "删除", operDesc = "删除", modular = "PC")
    public ResultUtil<T> delete(HttpServletRequest request, @PathVariable("id") Long id) {
        ResultUtil<T> result = sysWxRoleService.updateDelete(id);
        return result;
    }

    /**
     * 微信角色修改
     * @param request
     * @param sysWxRole
     * @return
     */
    @PostMapping("/editRet")
    @SysTemLog(operModul = "微信角色", operType = "修改", operDesc = "编辑", modular = "PC")
    public ResultUtil<T> editRet(HttpServletRequest request,@RequestBody SysWxRole sysWxRole) {
        ResultUtil<T> result = sysWxRoleService.updateRet(request, sysWxRole);
        return result;
    }

    @PostMapping("/grantRoleRet")
    @SysTemLog(operModul = "微信角色", operType = "授权", operDesc = "授权", modular = "PC")
    public ResultUtil<T> grantRoleRet(@RequestBody SysWxRoleVo data) {
        ResultUtil<T> result = sysWxRoleService.updateGrantRoleRet(data.getRoleid(), data.getData());
        return result;
    }

    /**
     * 角色授权回显
     */
    @RequestMapping("/getWxUserMenuList")
    public ResultUtil<List<Long>> getWxUserMenuList(@RequestBody SysWxRoleVo vo) {
        List<Long> userList = sysWxRoleService.getWxUserMenuList(vo.getId());
        return ResultUtil.build(userList, ResultUtilCodeEnum.SUCCESS);
    }
}
